package indi.jp.project.business.pub.controller;

import indi.jp.project.business.pub.pojo.po.ProjectPO;
import indi.jp.project.business.pub.pojo.query.ProjectQuery;
import indi.jp.project.core.entity.JsonResult;
import indi.jp.project.business.pub.service.ProjectService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * (PubProject)表控制层
 *
 * @author makejava
 * @since 2021-08-16 10:04:19
 */
@RestController
@RequestMapping("/pub/project")
public class ProjectController {

    @Resource
    private ProjectService projectService;

    @GetMapping("/queryGrid")
    public JsonResult queryGrid(ProjectQuery query, HttpServletRequest request) throws Exception {
        String account = request.getParameter("account");
        query.setLander(account);
        return projectService.queryGrid(query);
    }

    @PostMapping("/save")
    public JsonResult save(@RequestBody @Valid ProjectPO projectPO, HttpServletRequest request) throws Exception {
        String account = request.getParameter("account");
        projectPO.setCreateBy(account);
        projectPO.setModifyBy(account);
        return projectService.save(projectPO);
    }

    @PostMapping("/deleteById")
    public JsonResult deleteById(@RequestParam String id) throws Exception {
        return projectService.deleteById(id);
    }

    @GetMapping("/findById")
    public JsonResult findById(@RequestParam String id) throws Exception {
        return projectService.findById(id);
    }

}
